import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_navigation/src/routes/route_middleware.dart';
import 'package:umeng_common_sdk/umeng_common_sdk.dart';
import '../utils/utils.dart';

// import 'package:sports/logic/service/um_service.dart';
// import 'package:sports/res/routes.dart';
// import 'package:umeng_common_sdk/umeng_common_sdk.dart';

class UmengMiddleware extends GetMiddleware {
  @override
  RouteSettings? redirect(String? route) {
    return super.redirect(route);
  }

  String? route;

  @override
  GetPage? onPageCalled(GetPage? page) {
    route = page?.name;
    if (page != null) {
      Utils.pageStart(route);
      UmengCommonSdk.onPageStart(page.name);
    }
    return super.onPageCalled(page);
  }

  @override
  void onPageDispose() {
    // log('${Get.currentRoute}');
    // if (Get.currentRoute == Routes.navigation) {
    //   Get.find<UmService>().payOriginRoute = '';
    // }
    if (route != null) {
      Utils.pageEnd(route);
      UmengCommonSdk.onPageEnd(route!);
    }
  }
}
